﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace TransManage
{
    public partial class 高可用 : Form
    {
        public NetworkInterface[] networkInterfaces;
        public 高可用()
        {
            InitializeComponent();
            networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           // networkInterfaces = networkInterfaces;
            AddVirtualIP("\"hddEthernet\"", "static 192.168.5.111 255.255.255.0");
        }



        public  void AddVirtualIP(string adapterName, string ipAddress)
        {
            string command = $"netsh interface ip add address {adapterName} {ipAddress}";
            //netsh interface ip add address hddEthernet static 192.168.5.111 255.255.255.0
            ExecuteCommand(command);
        }

        private  void ExecuteCommand(string command)
        {
            using (Process process = new Process())
            {
                process.StartInfo.FileName = "cmd.exe";
                process.StartInfo.RedirectStandardInput = true;
                process.StartInfo.UseShellExecute = false;
                process.Start();

                process.StandardInput.WriteLine(command);
                process.StandardInput.WriteLine("exit");
                process.WaitForExit();
            }
        }
    }
}
